/*----------------------------------------------------------------------------------------
*
*  Copyright 2019, Gao Hai Hui, <fromzeropoint@126.com>.  All rights reserved.
*  https://gitee.com/helloworldghh/xoskit.git
*  Use of this source code is governed by a MIT license
*  that can be found in the License file.
*
----------------------------------------------------------------------------------------*/
#ifndef __37F9D32B_31F4_455b_BEDD_5E9BE1EF8F71__
#define __37F9D32B_31F4_455b_BEDD_5E9BE1EF8F71__

#include "../msg/head.h"

namespace xos_log
{

    class log_module;
    class log_msg;

    class mgr : public i_log_mgr
    {
    public:
        typedef xos::release_impl< mgr > T;

    public:
        mgr();
        ~mgr();

    public:
        static int static_init( xos_container::i_container* pContainer, i_log_mgr** ppv );
        static xos_container::i_container* container();
        static xos_box::i_callback* callback();
        static mgr* get();

    public:
        // 
        // 设置公共线程，所有日志消息都扔到这个线程中处理。公用线程能节省，少用一些线程，代码也清楚一些
        // 
        int set_work_thread( xos_box::i_callback * pWorkThread );

        // 
        // 添加日志输出方式
        // 
        int add_logger( i_logger * pLogger );
        i_log_file* file();
        i_logger* debug();
        i_logger* cmd();
        
        // 生成i_log_msg
        int notify( i_log_msg *& pMsg );
        i_log_msg * msg();

        // 
        // 日志开关
        // 
        int enable( bool bEnable );
        int flush();

    public:
        static int on_msg( xos_box::i_msg *& pMsg );
        int proc( xos_box::i_msg *& pMsg );
        int helper_flush();

    protected:
        int notify( enumMsg eMsg, log_msg *& pLogMsg );
        int init_data();

    public:
        int put_back_to_pool();
        int init();
        int term();

    protected:
        bool m_bEnableLog;

    };

} // xos_log

#endif // __37F9D32B_31F4_455b_BEDD_5E9BE1EF8F71__
